package com.peter.ai.util;

import java.io.File;

import com.peter.ai.voice.AliClientInstance;

public class AliyunThread extends Thread {

	private int index;
	private File[] files;
	private String mp3Dir;
	private int from=0;
	private int to=0;

	public AliyunThread(int index, File[] files, String mp3Dir,int from,int to) {
		this.index = index;
		this.files = files;
		this.mp3Dir = mp3Dir;
		this.from = from;
		this.to = to;
	}

	@Override
	public void run() {
		int size = (to-from)/ 10;
		int other = 0;
		for (File file : files) {
			int i = Integer.parseInt(file.getName().substring(0, 4));
			if (index==9) {
				other = (to-from)%10;
			}
			if (file.getName().contains(".txt") && i >= (index * size+from) && i < ((index + 1) * size+from+other)&&i<=to) {
				String text = FileUtils.readFile(file.getAbsolutePath());
				File temp = new File(mp3Dir+file.getName().substring(0, file.getName().indexOf("."))+".mp3");
				if (!temp.exists()) {
					AliClientInstance.text2Voice(text, mp3Dir, file.getName().substring(0, file.getName().indexOf(".")));
				}
			}
		}
	}
}
